<template>
    <el-alert
        title="每日一句"
        type="success"
        :description="hitokoto"
        :closable="false"
      />

    <el-alert
        title="js 每日一句"
        type="warning"
        :description="hitokotojs"
        :closable="false"
    />
</template>

<script setup lang="ts">
import { onBeforeMount, ref } from 'vue';
import { DailySentenceGo } from '../wailsjs/go/utool/App';
import { ElNotification } from 'element-plus';

const hitokoto = ref('airvip is a boy!')
const hitokotojs = ref('D:...')

onBeforeMount(() => {

    /* setInterval(() => {
        DailySentenceGo().then(res => {
            if(res.code != 1){
                ElNotification.error({
                    title: res.msg
                })
                return
            }
            hitokoto.value = res.data.hitokoto 
            if(res.data.from) {
                hitokoto.value += "    《 " + res.data.from + " 》"
            }
        })
    }, 10000) */

    // setInterval(() => {
        fetch('https://v1.hitokoto.cn')
            .then(response => response.json())
            .then(data => {
                hitokotojs.value = data.hitokoto
                if(data.from) {
                    hitokotojs.value += "    《 " + data.from + " 》"
                }
            })
            .catch(console.error)
    // }, 5000)
    
})

</script>